using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace JYJ.AiYard.Migrations
{
    public partial class AddUPdateDemoBook : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Books");

            migrationBuilder.DropColumn(
                name: "Author",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "BookType",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "Buyable",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "CoverImgUrl",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "CreationTime",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "CreatorUserId",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "Intro",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "LastModificationTime",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "LastModifierUserId",
                schema: "CMS",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "TenantId",
                schema: "CMS",
                table: "Books");

            migrationBuilder.EnsureSchema(
                name: "Demo");

            migrationBuilder.RenameTable(
                name: "Books",
                schema: "CMS",
                newName: "Books",
                newSchema: "Demo");

            migrationBuilder.AlterColumn<DateTime>(
                name: "PublishDate",
                schema: "Demo",
                table: "Books",
                nullable: false,
                oldClrType: typeof(DateTimeOffset),
                oldMaxLength: 65,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                schema: "Demo",
                table: "Books",
                maxLength: 65,
                nullable: false,
                oldClrType: typeof(string),
                oldMaxLength: 65,
                oldNullable: true);

            migrationBuilder.AddColumn<float>(
                name: "Price",
                schema: "Demo",
                table: "Books",
                nullable: false,
                defaultValue: 0f);

            migrationBuilder.AddColumn<byte>(
                name: "Type",
                schema: "Demo",
                table: "Books",
                maxLength: 65,
                nullable: false,
                defaultValue: (byte)0);

            migrationBuilder.CreateTable(
                name: "DemoBooks",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    CoverImgUrl = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    Author = table.Column<string>(nullable: true),
                    Intro = table.Column<string>(nullable: true),
                    BookType = table.Column<int>(nullable: false),
                    Buyable = table.Column<bool>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    PublishDate = table.Column<DateTimeOffset>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DemoBooks", x => x.Id);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DemoBooks");

            migrationBuilder.DropColumn(
                name: "Price",
                schema: "Demo",
                table: "Books");

            migrationBuilder.DropColumn(
                name: "Type",
                schema: "Demo",
                table: "Books");

            migrationBuilder.EnsureSchema(
                name: "CMS");

            migrationBuilder.RenameTable(
                name: "Books",
                schema: "Demo",
                newName: "Books",
                newSchema: "CMS");

            migrationBuilder.AlterColumn<DateTimeOffset>(
                name: "PublishDate",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: true,
                oldClrType: typeof(DateTime));

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: true,
                oldClrType: typeof(string),
                oldMaxLength: 65);

            migrationBuilder.AddColumn<string>(
                name: "Author",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "BookType",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<bool>(
                name: "Buyable",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<string>(
                name: "CoverImgUrl",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "CreationTime",
                schema: "CMS",
                table: "Books",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<long>(
                name: "CreatorUserId",
                schema: "CMS",
                table: "Books",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Intro",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastModificationTime",
                schema: "CMS",
                table: "Books",
                nullable: true);

            migrationBuilder.AddColumn<long>(
                name: "LastModifierUserId",
                schema: "CMS",
                table: "Books",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "TenantId",
                schema: "CMS",
                table: "Books",
                maxLength: 65,
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "Books",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(maxLength: 128, nullable: false),
                    Price = table.Column<float>(nullable: false),
                    PublishDate = table.Column<DateTime>(nullable: false),
                    Type = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Books", x => x.Id);
                });
        }
    }
}
